<?php

namespace app\admin\controller;

use app\common\controller\AdminController;

use common\Common;

use app\common\model\UtilConfig;


/**
 * 后台系统配置操作控制器
 * @name BaseConfig.php
 * @package qjdc
 * @category controller
 * @link www.changekeji.com
 * @author cd
 * @version 5.0
 * @copyright CHANGE INC
 * @since 2019-06-03
 */
class BaseConfig extends AdminController
{
    protected $LibConfig;

    /**
     * 构造函数
     */
    public function __construct()
    {
        $this->LibConfig = new UtilConfig('blf_config');
        $this->rightVerify(session('admin'), url("admin/Login/login"));
        parent::__construct();
    }


    /**
     * 系统配置页面
     */
    public function configList()
    {
        $this->getSetMenu($this);
        $group = 'system';
        $configResult = $this->LibConfig->findAllConfigComplete($group);
        $this->assign('configInfo', $configResult['data']);
        //日志记录
        $this->log(__CLASS__, __FUNCTION__, "系统配置页面", 1, 'view');
        return $this->fetch("BaseConfig/configList");
    }

    /**
     * 设置配置
     */
    public function setFeeRatioConfig()
    {
        $configInfo = $this->getConfigInfo($this->LibConfig);
        $result = $this->LibConfig->updateConfig($configInfo);
        //日志记录
        $this->log(__CLASS__, __FUNCTION__, "设置配置", 0, 'edit');
        echo json_encode($result);
    }


    /**
     * 构造修改信息
     * @param string lib_config
     * @return array
     */
    private function getConfigInfo($LibObj)
    {
        $configInfo = array();
        $arr = array('system');
        $result = $LibObj->findAllConfigComplete($arr);//获取所有配置$result['data']
        foreach ($result['data'] as $per) {
            $configInfo[$per['item_key']] = input("param." . $per['item_key']);
        }
        return $configInfo;
    }
}